<template>
<view>
<!--<nav-bar navbar-data='{{nvabarData}}'></nav-bar>-->
<image class="bg-img" src="http://imgbdb3.bendibao.com/whbdb/202010/21/20201021161753_22900.png"></image>
<view class="body">
  <image class="logo" mode="aspectFit" src="http://imgbdb3.bendibao.com/whbdb/202010/21/20201021161848_80607.png"></image>
  <text class="text-1">点击登录</text>
  <button @tap="getuserinfo" class="bind-tel">
    微信用户授权登录
  </button>
</view>
</view>
</template>

<script>
// 登录页面
const app = getApp();
const util = require("../../../utils/util.js");
var getUserInfo;
let type;

export default {
  data() {
    return {};
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    type = options.type;
    util.getUrl(app.globalData.url);
  },
  methods: {
    getuserinfo(e) {
      uni.getUserProfile({
        desc: "用于展示用户信息",
        success: res => {
          uni.setStorageSync("userInfo", res.userInfo);
          let loginData = {
            action: "userInfo",
            session_key: uni.getStorageSync("session_key"),
            encryptedData: res.encryptedData,
            iv: res.iv,
            userInfo: JSON.stringify(res.userInfo),
            openid: uni.getStorageSync('openid') || '',
            unionid: uni.getStorageSync('unionid') || ''
          };
          util.request('user.php', loginData, 'POST').then(res => {
            if (res.data.state == 1) {
              uni.setStorageSync("user_id", res.data.data.user_id);
              uni.navigateBack({
                delta: 1
              });
            } else uni.showToast({
              title: '登录失败，请检查微信是否更新到最新版',
              icon: 'none'
            });
          });
        },
        fail: () => {
          uni.showToast({
            title: '请授权后再登录',
            icon: 'none'
          });
        }
      });
    }

  }
};
</script>
<style>
/* pages/self/getPhone.wxss */

page {
    height: 100%;
}

.body {
    height: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
}

.bg-img {
    position: absolute;
    top: 0;
    height: 100%;
    width: 100%;
}

.text-1 {
    font-size: 38rpx;
    color: #343434;
    font-weight: bold;
    margin-bottom: 8rpx;
}

.text-2 {
    font-size: 28rpx;
    color: #828282;
}

.bind-tel {
    width: 409rpx;
    height: 94rpx;
    margin-top: 84rpx;
    line-height: 94rpx;
    color: #fff;
    background: linear-gradient(to right, #07D96E, #00C45A);
    font-size: 34rpx;
    border-radius: 48rpx;
}

.logo {
    width: 464rxp;
    height: 222rpx;
}
</style>